package com.kongxx.struts2study.fileupload.web.action;

import java.io.File;

import org.apache.commons.io.FileUtils;

import com.kongxx.struts2study.common.web.action.BaseAction;

public class FileUploadAction extends BaseAction {
	
	private static final long serialVersionUID = 1L;
	
	private File myFile;
	
	private String myFileContentType;
	
	private String myFileFileName;
	
	private String myFileCaption;

	public String toUpload() {
		return SUCCESS;
	}
	
	public String doUpload() {
		try {
			File theFile = new File("myfile.txt");
			FileUtils.copyFile(myFile, theFile);
		} catch (Exception e) {
			addActionError(e.getMessage());
			return INPUT;
		}
		return SUCCESS;
	}

	public File getMyFile() {
		return myFile;
	}

	public void setMyFile(File myFile) {
		this.myFile = myFile;
	}

	public String getMyFileContentType() {
		return myFileContentType;
	}

	public void setMyFileContentType(String myFileContentType) {
		this.myFileContentType = myFileContentType;
	}

	public String getMyFileFileName() {
		return myFileFileName;
	}

	public void setMyFileFileName(String myFileFileName) {
		this.myFileFileName = myFileFileName;
	}

	public String getMyFileCaption() {
		return myFileCaption;
	}

	public void setMyFileCaption(String myFileCaption) {
		this.myFileCaption = myFileCaption;
	}
}
